package com.xy.user.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.user.Employee;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.xy.user.service.EmployeeSkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/employeeskill")
public class EmployeeSkillController extends BaseController {
    @Autowired
    private EmployeeSkillService employeeSkillService;

    /**
     * 获取员工及其技能列表
     */
    @RequiresPermissions("user:employeeskill:query")
    @GetMapping(value = "/{id}")
    public R getEmployeeWithSkills(@PathVariable String id) {
        Employee employee = employeeSkillService.getEmployeeWithSkills(id);
        return R.ok(employee);
    }


    /**
     * 查询所有员工信息(有数据没分页)
     */
    @RequiresPermissions("user:employeeskill:list")
    @GetMapping("/list")
    public TableDataInfo getAllEmployees(Employee employee, @RequestParam(value = "skills", required = false, defaultValue = "") String skills) {
        // 判断是否有skills参数
        List<Employee> list;
        if (!Objects.equals(skills, "")) {
            employee.setSkills(skills);
            list = employeeSkillService.getAllEmployees(employee);
        } else {
            // 全量查询
            startPage();
            list = employeeSkillService.getAllEmployees(employee);
        }

        return getDataTable(list);
    }
}